package com.sjm.suchbear.minibookmall;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sjm.suchbear.minibookmall.action.BookManage;
import com.sjm.suchbear.minibookmall.model.BookModel;
import com.sjm.suchbear.minibookmall.model.OrderDetailModel;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Suchbear on 2018/5/10.
 */
public class OrderDetailAdapter extends BaseAdapter {
    private ViewHolder viewHolder;
    private Context context;
    private List<OrderDetailModel> orderDetailModels;

    public OrderDetailAdapter(Context context, List<OrderDetailModel> orderDetailModels) {
        this.context = context;
        this.orderDetailModels = orderDetailModels;
    }

    @Override
    public int getCount() {
        if (orderDetailModels != null) {
            return orderDetailModels.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return orderDetailModels.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_show, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvName.setText(orderDetailModels.get(i).getBookName());
        viewHolder.tvSec.setText(orderDetailModels.get(i).getNum().concat("本"));
        viewHolder.tvPrice.setText("¥".concat(orderDetailModels.get(i).getPrice()));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_sec)
        TextView tvSec;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.ll_all)
        LinearLayout llAll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
